package com.ctgu.service.impl;

import com.ctgu.mapper.CourseMapper;
import com.ctgu.service.CourseService;
import com.ctgu.vo.Course;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Resource
    private CourseMapper courseMapper;


    @Override
    public List<Course> getCourseByUserId(Integer id) {
        return courseMapper.selectCourseByStudentId(id);
    }

    @Override
    public List<Course> getAllCourse() {
        return courseMapper.selectAllCourse();
    }

    @Override
    public List<Course> getCourseByTeacherId(Integer id) {
        return courseMapper.getCourseByTeacherId(id);
    }

    @Override
    public void addClass(String courseId, String courseName, Integer teacherId, String courseDetail) {
        Course course = new Course();
        course.setCourseId(courseId);
        course.setCourseName(courseName);
        course.setTeacherId(teacherId);
        if(courseDetail == null){
            course.setCourseDetail("");
        }else{
            course.setCourseDetail(courseDetail);
        }
        courseMapper.insert(course);
    }

    @Override
    public List<Course> offerCourse() {
        return courseMapper.offerCourse();
    }

    @Override
    public void deletecourse(String courseId) {
        courseMapper.deleteByPrimaryKey(courseId);
    }
}
